package com.bite.aop;

import com.bite.aop.controller.TestController;
import com.bite.aop.proxy.HouseSubject;
import com.bite.aop.proxy.RealHouseSubject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringAopApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(SpringAopApplication.class, args);

//		//设置spring.aop.proxy-target-class=false
//		//测试代理类的情况, 结论: CGLIb代理
//		TestController bean = context.getBean(TestController.class);
//		System.out.println(bean.getClass().toString());
//		//测试代理接口 结论: JDK代理
//		//修改代码内容, 给RealHouseSubject 添加@Component
////		HouseSubject bean1 = (HouseSubject)context.getBean("realHouseSubject");
////		System.out.println(bean1.getClass().toString());
//		//把接口改成类, 以下代码会报错
//		RealHouseSubject bean1 = (RealHouseSubject)context.getBean("realHouseSubject");
//		System.out.println(bean1.getClass().toString());


		//设置spring.aop.proxy-target-class=true  (默认)
		//测试代理类的情况, 结论: CGLib
		TestController bean = context.getBean(TestController.class);
		System.out.println(bean.getClass().toString());
		//测试代理接口 结论: CGLib
		//修改代码内容, 给RealHouseSubject 添加@Component
//		HouseSubject bean1 = (HouseSubject)context.getBean("realHouseSubject");
//		System.out.println(bean1.getClass().toString());
		//把上面接口改成类, 代码不会报错
		RealHouseSubject bean1 = (RealHouseSubject)context.getBean("realHouseSubject");
		System.out.println(bean1.getClass().toString());
	}

}
